// pages/my/my.js
const config = require('../../config.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // ishy:1,
    userInfos: {},
    typeData: {},
    typeVip: '',
  },
  openUp: function () {
    wx.navigateTo({
      url: '/pages/card/card'
    })
  },
  seeInfo:function () {
    wx.navigateTo({
      url: '/pages/personal/personal'
    })
  },
  goWallet: function () {
    wx.navigateTo({
      url: '/pages/wallet/wallet'
    })
  },
  seeRecord: function () {
    wx.navigateTo({
      url: '/pages/record/record'
    })
  },
  goOpen: function () {
    wx.navigateTo({
      url: '/pages/casual/casual'
    })
  },
  goFeedback: function () {
    wx.navigateTo({
      url: '/pages/feedback/feedback'
    })
  }, 

  // 获取会员卡类型
  getVip: function () {
    var that = this;
    wx.request({
      url: config.vipType,
      method: 'GET',
      data: {
      },
      header: {
        'content-type': 'application/json',
        'Authorization': wx.getStorageSync('token_type') + ' ' + wx.getStorageSync('access_token'),
      },
      success: function (res) {
        wx.hideLoading();
        that.setData({
          typeData: res.data.data
        })
        console.log(res, "result")
      }
    })
  }, 

  // 查看会员卡详情
  seeVip: function (e) {
    console.log(e)
    if (e.currentTarget.dataset.type == "月卡") {
      this.setData({
        typeVip: '月卡规则'
      })
    } else if (e.currentTarget.dataset.type == "季卡") {
      this.setData({
        typeVip: '季卡规则'
      })
    } else if (e.currentTarget.dataset.type == "年卡") {
      this.setData({
        typeVip: '年卡规则'
      })
    }
    // var that = this;
    wx.navigateTo({
      url: '/pages/card_detail/card_detail?type=' + this.data.typeVip,
    })
  }, 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getUserinfo();
    this.getVip();
  },
  // 拿到已有用户信息
  getUserinfo: function () {
    var that = this;
    wx.request({
      url: config.initUser,
      method: 'GET',
      data: {
      },
      header: {
        'content-type': 'application/json',
        'Authorization': wx.getStorageSync('token_type') + ' ' + wx.getStorageSync('access_token'),
      },
      success: function (res) {
        wx.hideLoading();
        that.setData({
          userInfos: res.data.data,
        })
        // console.log(res, "userInfores")
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getUserinfo();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})